import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../common/system_config.dart';
import '../utils/tools/localstorage_tool.dart';


class ThemeModel with ChangeNotifier{
  ThemeData themeData;// 定义主题风格
  ThemeType currentType;// 定义主题类型

  /// 构造函数
  ThemeModel(String type) {
    if (type == null || type == "ThemeType.light") {
      currentType = ThemeType.light;
      themeData = light;
    } else {
      currentType = ThemeType.dark;
      themeData = dark;
    }
  }

  /// 切换主题（高亮/暗夜两种模式切换）
  void reverse() {
    if (currentType == ThemeType.light) {
      _updateTheme(ThemeType.dark);
    } else {
      _updateTheme(ThemeType.light);
    }
  }

  /// 更新主题
  /// * [type] ThemeType|主题类型|必填
  void _updateTheme(ThemeType type) {
    currentType = type;

    // 存储主题信息
    LocalStorage.setStringItem("themeContext", currentType.toString());

    // 判断当前主题类型
    if (type == ThemeType.light) {
      themeData = light;
    } else {
      themeData = dark;
    }

    // 更新通知
    notifyListeners();
  }

}

// 主题类型
enum ThemeType {
  light,
  dark,
}

// 定义高亮风格
ThemeData light = ThemeData(
  brightness: Brightness.light,
  primaryColor: SystemConfig.themeColor,
  backgroundColor: Color(0xffffffff),
  textTheme: TextTheme(
    headline: TextStyle(color: SystemConfig.themeColor, fontSize: 10),
  ),
);

// 定义深夜风格
ThemeData dark = ThemeData(
  brightness: Brightness.dark,
  backgroundColor: Colors.black,
  textTheme: TextTheme(
    headline: TextStyle(color: SystemConfig.themeColor),
  ),
);














